let $doc = $(document);
let common={
    init:function () {
        this.nav();
    },
    nav: function () {
        //初始化导航动画条，初始位置，初始宽度
        let $bar = $('.slide-bar'),//滑动的条
            $active = $('.nav-active'),//当前页面的激活状态
            $nav = $('.nav-list'),//导航列表
            $base = parseInt($active.css('padding-left')) * 2,//PADDING基数
            $startWidth = $active.width() + $base,
            $startPosition = $active.offset().left - $nav.offset().left,
            navObj = {
                navInit: function () {
                    $bar.css({left: $startPosition, width: $startWidth});
                    navObj.onResize();
                    navObj.onHover();
                },
                onResize: function () {
                    //窗口响应后重新计算
                    $(window).resize(function () {
                        $base = parseInt($active.css('padding-left')) * 2;
                        $startWidth = $active.width() + $base;
                        $startPosition = $active.position().left - $nav.position().left;
                        $bar.css({left: $startPosition, width: $startWidth});
                    })
                },
                //事件处理
                onHover: function () {
                    $doc.on('mouseenter', '.nav-list .sub1', function (e) {
                        let $this = $(this),
                            $left = $this.offset().left - $nav.offset().left,
                            $width = $this.width() + $base;
                        $bar.css({left: $left, width: $width});
                        $('.slide-inner').addClass('move');
                        setTimeout(function () {
                            $('.slide-inner').removeClass('move');
                        }, 360);
                    });
                    $doc.on('mouseleave', '.nav-list .sub1', function (e) {
                        $bar.css({left: $startPosition, width: $startWidth});
                    })
                }
            };
        navObj.navInit();

    },
    event:function () {

    }
};
common.init();

//扩展
$.extend({
    'tipTop': function (bool, text, time) {
        let tipText = text,
            _time = time ? time : 3000;
        if (bool === true) {
            tipText = '<div class="tip-top-ok"><i></i>' + tipText + '</div>';
        } else {
            tipText = '<div class="tip-top-warn"><i></i>' + tipText + '</div>';
        }
        let tipDialog = dialog({
            content: tipText,
            skin: 'min-dialog tips',
            zIndex: 2000
        });
        tipDialog.show();
        setTimeout(function () {
            tipDialog.close().remove();
        }, _time);
    },
    'tipMore': function ($container) {
        $('.icon-tip', $container).each(function () {
            let $this = $(this);
            if ($this.offset().left > 895) {
                $this.find('.favicon-case').css({'left': 'auto', 'right': '320px', 'z-index': 10});
                $this.find('.triangle').css({'left': 'auto', 'right': '-9px', 'transform': 'rotate(180deg)'});
            }
        });
    },
    'waiting': function (text) {
        let waitingDom = '<div class="updating"><img src="//img-i.westarcloud.com/2018/0920/uyqahyncuadtzsds055805.gif" alt=""></div><span>' + text + '</span>\n';
        let waitDialog = dialog({
            content: waitingDom,
            zIndex: 2000,
            skin: 'update-pop'
        });
        return waitDialog;
    }
});
